package com.example.databasepj.controller;

import com.example.databasepj.Request.*;
import com.example.databasepj.dto.MerchantCompleteInfo;
import com.example.databasepj.dto.MerchantGetMenu;
import com.example.databasepj.dto.MerchantOrderResponse;
import com.example.databasepj.dtoAdvanced.FanConsumptionRequest;
import com.example.databasepj.dtoAdvanced.FansConsumptionResponse;
import com.example.databasepj.dtoAdvanced.FansRequest;
import com.example.databasepj.dtoAdvanced.FansResponse;
import com.example.databasepj.service.DishService;
import com.example.databasepj.service.MerchantService;
import com.example.databasepj.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/merchant")
public class MerchantController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private MerchantService merchantService;
    @Autowired
    private DishService dishService;
    @PutMapping ("/updateOrderStatus") //商户更新订单状态，完成订单
    @ResponseBody
    public void updateOrderStatus(@RequestBody OrderStatusRequest orderRequest){
        orderService.updateOrderStatus(orderRequest.getOrder_ID(),orderRequest.getOrder_status());
    }

    @GetMapping("/GetMenu/{merchant_ID}") //用户查看一个商家的菜单
    @ResponseBody
    public List<MerchantGetMenu> getMerchantMenu(@PathVariable int merchant_ID){
        return merchantService.merchantGetMenuAndData(merchant_ID);
    }

    @PostMapping ("/addDish") //商家添加新菜品
    @ResponseBody
    public void addDish(@RequestBody DishInsertRequest request){
        dishService.insertDish(request);
    }

    @PostMapping("/updateDish/{dish_ID}") //商家编辑某个菜品
    @ResponseBody
    public void updateDish(@PathVariable int dish_ID,
                           @RequestBody DishUpdateRequest request){
        dishService.updateDish(request);
    }

    @PostMapping("/deleteDish") //商家删除某个菜品
    @ResponseBody
    public void deleteDish(@RequestBody DishDeleteRequest request){
        dishService.deleteDish(request);
    }
    ///getOrders/{merchantId}
    @GetMapping("/getOrders/{merchantId}") //商家获取自己的订单
    @ResponseBody
    public List<MerchantOrderResponse> getOrders(@PathVariable int merchantId){
        return orderService.merchantGetOrders(merchantId);
    }

    @PutMapping ("/updateMerchantInfo/{merchant_ID}") //修改商户信息
    @ResponseBody
    public void updateMerchant(@PathVariable int merchant_ID,
                               @RequestBody MerchantUpdateRequest request){
        merchantService.updateMerchantInfo(merchant_ID,request);
    }
    @GetMapping("/getMerchantInfo/{merchantId}") //用户查看一个商家的菜单
    @ResponseBody
    public MerchantCompleteInfo getMerchantInfo(@PathVariable int merchantId){
        return merchantService.getMerchantCompleteInfo(merchantId);
    }

    @PostMapping("/getFans") //商家获取忠实粉丝列表
    @ResponseBody
    public List<FansResponse> getFans(@RequestBody FansRequest request){
        return orderService.getFans(request);
    }

    @PostMapping("/fan-consumption") //商家获取某一个忠实粉丝消费分布
    @ResponseBody
    public List<FansConsumptionResponse> getFanConsumption(@RequestBody FanConsumptionRequest request){
        return orderService.getFansConsumption(request);
    }






}
